<template>
  <!-- STP设置审核明细-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form ref="form" :model="form" :rules="rules" :disabled="true" label-width="110px">
      <!--STP设置审核明细-->

      <el-row>
        <el-col :span="12">
          <el-form-item label="non-STP类型" prop="nstpType">
            <el-select v-model="form.nstpType" placeholder="non-STP类型" style="width: 100%">
              <el-option
                v-for="dict in dictMap.STP_TYPE"
                :key="dict.value"
                :label="`${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="来往账标志" prop="drct">
            <el-select v-model="form.drct" placeholder="来往账标志" style="width: 100%">
              <el-option
                v-for="dict in dictMap.DRCTCODE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="启用标志" prop="status">
            <el-select v-model="form.status" placeholder="启用标志" style="width: 100%">
              <el-option
                v-for="dict in dictMap.ON_OFF_STATUS"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12" v-show="form.nstpType == 13 && form.status == 1">
          <el-form-item label="往账大金额下限" prop="nstpAmount">
            <ht-amount-input v-model="form.nstpAmount" placeholder="往账大金额下限" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24" v-show="form.nstpType == 11 && form.status == 1">
          <el-form-item label="重账要素" prop="dupEle">
            <el-checkbox-group v-model="dupEleList">
              <el-checkbox v-for="dict in dictMap.DUP_ELE" :key="dict.value" :label="dict.value" :value="dict.value">
                {{ dict.text }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row>
      <div v-show="(form.nstpType == 12 || form.nstpType == 21) && form.opType != ''">
      <el-row>
      <el-col :span="12">
        <el-form-item label="操作类型" prop="opType">
          <el-select v-model="form.opType" placeholder="操作类型" style="width: 100%">
            <el-option
              v-for="dict in dictMap.OP_TYPE"
              :key="dict.value"
              :label="`${dict.value}-${dict.text}`"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="报文类型" prop="pkgno">
            <el-select style="width: 100%" v-model="form.pkgno" placeholder="报文类型">
              <el-option
                v-for="dict in dictMap.STP_PKGNO"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="校验字段" prop="field">
            <el-select v-model="form.field" placeholder="校验字段">
              <el-option
                v-for="dict in fieldList"
                :key="dict.value"
                :label="`${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="检验方式" prop="keystyle">
            <el-select style="width: 100%" v-model="form.keystyle" placeholder="检验方式">
              <el-option
                v-for="dict in dictMap.KEYSTYLE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="关键字" prop="keyWord">
            <el-input v-model="form.keyWord" placeholder="关键字" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="reMark">
            <el-input type="textarea" v-model="form.reMark" placeholder="备注" />
          </el-form-item>
        </el-col>
      </el-row>
      </div>

      <el-row>
        <el-col :span="12">
          <el-form-item label="录入操作员" prop="mdTlrno">
            <el-input v-model="form.mdTlrno" placeholder="录入操作员" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="录入时间" prop="mdTime">
            <el-date-picker style="width: 100%" v-model="form.mdTime" value-format="yyyyMMddHHmmss" type="datetime" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="approve">审 核</el-button>
      <el-button type="primary" @click="reject">拒 绝</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { stpInstallApproveDetail, stpInstallApprove, stpInstallReject } from "@/api/cnaps/bizMng/stpInstall.js";
import { listPageMixin } from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput";

export default {
  name: "stpInstallApproveDialog",
  mixins: [listPageMixin],
  components: {
    HtAmountInput,
  },
  data() {
    return {
      title: "",
      dupEleList: [],
      fieldList:[],
      // 是否显示弹出层
      openState: false,
      // 字段可编辑控制

      //数据字典
      searchFormDictList: ["STP_TYPE", "DRCTCODE", "ON_OFF_STATUS", "OP_TYPE", "DUP_ELE","KEYSTYLE"],
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      opButtonList: () => {
        return [];
      },
    };
  },
  mounted() {},
  methods: {
    // 表单重置
    reset() {
      this.resetForm("form");
      this.$set(this, "form", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {});
    },
    show(row) {
      this.form = row;
      this.title = "STP设置审核明细";
      this.openState = true;

      this.stpInstallApproveDetail(row);
    },

    /** 初始化重账要素 */
    initDupEle(row) {
      if (typeof row.dupEle !== "undefined") {
        this.dupEleList = row.dupEle.split(",");
      }

      let dictKeyPre = `STP_FIELD_${this.form.pkgno.toUpperCase()}`;
      this.getDicts(dictKeyPre).then((response) => {
        this.fieldList = response.result;
      });

    },
    stpInstallApproveDetail: function (row) {
      stpInstallApproveDetail(row).then((response) => {
        this.showData(response);
      });
    },
    showData: function (response) {
      this.form = response.result.data;
      this.initDupEle(this.form);
    },

    /** TODO审批按钮 */
    approve() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          stpInstallApprove(this.form).then((res) => {
            if (res.code === "S") {
              this.msgSuccess("审批通过");
              this.cancel();
            }
          });
        }
      });
    },

    /** TODO拒绝按钮 */
    reject() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          stpInstallReject(this.form).then((res) => {
            if (res.code === "S") {
              this.msgSuccess("审批已拒绝");
              this.cancel();
            }
          });
        }
      });
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", true);
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
